package com.ruoyi.system.service.impl;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.ruoyi.system.service.BarcodeService;
import org.springframework.stereotype.Service;

import java.awt.image.BufferedImage;

/**
 * 二维码生成类
 */
@Service
public class BarcodeServiceImpl implements BarcodeService {

    public BufferedImage generateBarcodeImage(String barcodeText) throws WriterException {
        QRCodeWriter barcodeWriter = new QRCodeWriter();
        String tt = barcodeText;
        BitMatrix bitMatrix = barcodeWriter.encode(barcodeText, BarcodeFormat.QR_CODE, 300, 150);

        return MatrixToImageWriter.toBufferedImage(bitMatrix);
    }
}
